﻿
var xmlhttp = false;
var httpXml = false;
function getHTTPRequestObject() {
    try {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e1) {
        try {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (e2) {
            xmlhttp = false;
        }
    }
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
        xmlhttp = new XMLHttpRequest();
    }
}

// cut space in first row and last row
function lTrim(sString) {
    while (sString.substring(0, 1) == ' ') {
        sString = sString.substring(1, sString.length);
    }
    return sString;
}


function rTrim(sString) {
    while (sString.substring(sString.length - 1, sString.length) == ' ') {
        sString = sString.substring(0, sString.length - 1);
    }
    return sString;
}
function Trim(sString) {
    sString = lTrim(sString);
    sString = rTrim(sString);
    return sString.replace('amp;', '');
}
function ChechWhiteSpace(__String) {
    try {
        if (__String = '') return true;
        for (var __s = 0; __s < __String.length; __s++) {
            if (__String.charAt(__s) == ' ')
                return false;
        }
        return true;
    } catch (err) {jAlert(err,'Error !'); }
}
function CheckEmail(__Email) {
    try {        
        return __Email.search(/^\w(\.?[\w-])*@\w(\.?[\w-])*\.[a-z]{2,4}$/i) == -1 ? false : true;
    }
    catch (error)
      {
    return false;
    }
}


///check number interger
function isInteger(s) {
    var i;
    for (i = 0; i < s.length; i++) {
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

///loading
function Loading(PopupWidth, PopupHeight, url) {
    var popup = $control('Loading');
    var __ClientHeight = document.body.clientHeight > document.body.scrollHeight ? document.body.clientHeight : document.body.scrollHeight;
    __ClientHeight = __ClientHeight < 600 ? 600 : __ClientHeight;
    $control('overlay').style.display = 'block';
    var scrolledX, scrolledY;
    if (self.pageYOffset) {
        scrolledX = self.pageXOffset;
        scrolledY = self.pageYOffset;
    }
    else if (document.documentElement && document.documentElement.scrollTop) {
        scrolledX = document.documentElement.scrollLeft;
        scrolledY = document.documentElement.scrollTop;
    }
    else if (document.body) {
        scrolledX = document.body.scrollLeft;
        scrolledY = document.body.scrollTop;
    }

    var centerX, centerY;
    if (self.innerHeight) {
        centerX = self.innerWidth;
        centerY = self.innerHeight;
    }
    else if (document.documentElement && document.documentElement.clientHeight) {
        centerX = document.documentElement.clientWidth;
        centerY = document.documentElement.clientHeight;
    }
    else if (document.body) {
        centerX = document.body.clientWidth;
        centerY = document.body.clientHeight;
    }

    // Xwidth is the width of the div, Yheight is the height of the
    // div passed as arguments to the function:
    var leftOffset = scrolledX + (centerX - PopupWidth) / 2;
    var topOffset = scrolledY + (centerY - PopupHeight) / 2;
    popup.style.width = parseInt(PopupWidth) + 'px';
    popup.style.height = parseInt(PopupHeight) + 'px';
    popup.style.left = parseInt(leftOffset) + 'px';
    popup.style.top = parseInt(topOffset) + 'px';
    //  popup.innerHTML = url;
    popup.style.display = 'block';
    __ClientHeight = __ClientHeight > scrolledY + centerY + 50 ? __ClientHeight : scrolledY + centerY + 50;
    $control('overlay').style.height = __ClientHeight + 'px';

    //  alert(scrolledX + (centerX - PopupWidth) + ':' + scrolledY + (centerY - PopupHeight));
    return false;
}


function UnLoading() {
    if ($control('overlay') !=null)
        $control('overlay').style.display = 'none';
    if ($control('ShowPopup') != null)
        $control('ShowPopup').style.display = 'none';
    if ($control('Loading') != null)
    $control('Loading').style.display = 'none';
}


function UnLoad() {
    if (typeof (ReloadData) == 'function')
        ReloadData();
}

var IsConfirm = false;
function Confirm(Messenger, Title, obj) {
    IsConfirm = true;
    jConfirm(Messenger, Title, function(r) {
        if (r) { obj.click(); Loading(100, 100, ''); }
        else IsConfirm = false;


    });

}



function ShowPopup(PopupWidth, PopupHeight, url, title) {
    var popup = $control('ShowPopup');
    var __ClientHeight = document.body.clientHeight > document.body.scrollHeight ? document.body.clientHeight : document.body.scrollHeight;
    __ClientHeight = __ClientHeight < 600 ? 600 : __ClientHeight;
    $control('overlay').style.display = 'block';
    var scrolledX, scrolledY;
    if (self.pageYOffset) {
        scrolledX = self.pageXOffset;
        scrolledY = self.pageYOffset;
    }
    else if (document.documentElement && document.documentElement.scrollTop) {
        scrolledX = document.documentElement.scrollLeft;
        scrolledY = document.documentElement.scrollTop;
    }
    else if (document.body) {
        scrolledX = document.body.scrollLeft;
        scrolledY = document.body.scrollTop;
    }

    var centerX, centerY;
    if (self.innerHeight) {
        centerX = self.innerWidth;
        centerY = self.innerHeight;
    }
    else if (document.documentElement && document.documentElement.clientHeight) {
        centerX = document.documentElement.clientWidth;
        centerY = document.documentElement.clientHeight;
    }
    else if (document.body) {
        centerX = document.body.clientWidth;
        centerY = document.body.clientHeight;
    }

    // Xwidth is the width of the div, Yheight is the height of the
    // div passed as arguments to the function:
    var leftOffset = scrolledX + (centerX - PopupWidth) / 2;
    var topOffset = scrolledY + (centerY - PopupHeight) / 2;
    popup.style.width = parseInt(PopupWidth) + 'px';
    popup.style.height = parseInt(PopupHeight) + 'px';
    popup.style.left = parseInt(leftOffset) + 'px';
    popup.style.top = parseInt(topOffset) + 'px';
    __ClientHeight = __ClientHeight > scrolledY + centerY ? __ClientHeight : scrolledY + centerY;
    var Height = (__ClientHeight - PopupHeight) / 2;
    var Width = (document.body.clientWidth - PopupWidth) / 2;
    $control('overlay').style.height = __ClientHeight + 'px';
    popup.innerHTML = div(parseInt(PopupWidth), parseInt(PopupHeight), parseInt(Width), parseInt(Height), url, title);
    popup.style.display = 'block';
    return false;
}
function div(width, height, left, top, url, title) {
    return '<table width="100%" border=\"0\" cellspacing="0" cellspadding="0"><tr  class="HeadPopup"><td style="text-align:left;width:90%"><h1 id="Modelpopup_title" style="cursor: move;border:none">' + title.toUpperCase() + '</h1></td><td style="text-align:right;width:10%"><h1  id="Modelpopup_title" onclick="UnLoading();UnLoad();" style="cursor: Pointer;border:none">Close</h1></td></tr><tr class="ContentPopup"><td colspan=\"2\" style="text-align:center;width:100%"><iframe width="100%" style="border: none;text-align:left" scrolling="auto" height="' + (height - 14) + '" src="' + url + '"></iframe></td></tr></table>';
}


function PlayerShow(PopupWidth, PopupHeight, html, title) {
    var popup = $control('ShowPopup');
    var __ClientHeight = document.body.clientHeight > document.body.scrollHeight ? document.body.clientHeight : document.body.scrollHeight;
    __ClientHeight = __ClientHeight < 600 ? 600 : __ClientHeight;
   // alert($control('overlay'));
    $control('overlay').style.display = 'block';
    var scrolledX, scrolledY;
    if (self.pageYOffset) {
        scrolledX = self.pageXOffset;
        scrolledY = self.pageYOffset;
    }
    else if (document.documentElement && document.documentElement.scrollTop) {
        scrolledX = document.documentElement.scrollLeft;
        scrolledY = document.documentElement.scrollTop;
    }
    else if (document.body) {
        scrolledX = document.body.scrollLeft;
        scrolledY = document.body.scrollTop;
    }

    var centerX, centerY;
    if (self.innerHeight) {
        centerX = self.innerWidth;
        centerY = self.innerHeight;
    }
    else if (document.documentElement && document.documentElement.clientHeight) {
        centerX = document.documentElement.clientWidth;
        centerY = document.documentElement.clientHeight;
    }
    else if (document.body) {
        centerX = document.body.clientWidth;
        centerY = document.body.clientHeight;
    }

    // Xwidth is the width of the div, Yheight is the height of the
    // div passed as arguments to the function:
    var leftOffset = scrolledX + (centerX - PopupWidth) / 2;
    var topOffset = scrolledY + (centerY - PopupHeight) / 2;
    popup.style.width = parseInt(PopupWidth) + 'px';
    popup.style.height = parseInt(PopupHeight) + 'px';
    popup.style.left = parseInt(leftOffset) + 'px';
    popup.style.top = parseInt(topOffset) + 'px';
    __ClientHeight = __ClientHeight > scrolledY + centerY ? __ClientHeight : scrolledY + centerY;
    var Height = (__ClientHeight - PopupHeight) / 2;
    var Width = (document.body.clientWidth - PopupWidth) / 2;
    $control('overlay').style.height = __ClientHeight + 'px';
    popup.innerHTML = gethtmldebt(parseInt(PopupWidth), parseInt(PopupHeight), parseInt(Width), parseInt(Height), html, title);
    popup.style.display = 'block';
    return false;
}


function gethtml(width, height, left, top, html, title) {
    return '<table width="100%" border=\"0\" cellspacing="0" cellspadding="0"><tr  class="HeadPopup"><td style="text-align:left;width:90%"><h1 id="Modelpopup_title" style="cursor: move;border:none">' + title.toUpperCase() + '</h1></td><td style="text-align:right;width:10%"><h1  id="Modelpopup_title" onclick="UnLoading();" style="cursor: Pointer;border:none">Close</h1></td></tr><tr class="ContentPopup"><td colspan=\"2\" style="text-align:center;width:100%">' + html + '</td></tr></table>';
}

function gethtmldebt(width, height, left, top, html, title) {
    return '<table  width="100%" border=\"0\" cellspacing="0" cellspadding="0"><tr class="ContentPopup"><td colspan=\"2\" style="text-align:left;width:100%"><table style="width:100%;border:0px" cellpadding="0" cellspacing="0"><tr><td style="color:#000;padding-left:10px;font-size:14px;">' + html + '</td></tr><tr><td style="text-align:center;"><input id="accept" type="button"  style="cursor:pointer;" class="button_style" value="Xác nhận" onclick="acceptReActive();" /></td></tr></table><div style="float:right;position:absolute;margin-top:-50px;width:50px;height:50px;z-index: 1800;margin-left:440px;background-color:#;" ></div></td></tr></table>';
}

function ShowToolTip(sender, __ObjID, __ObjText, __add) {//alert(__ObjText);
    // alert(sender.id);
    SetSizeToolTip(sender, __ObjID, __add);
    $control(__ObjID).style.width = __ObjText.length + 'px';
    $control(__ObjID).style.height = '50px';
    var __Html = '<div class="chuthich_re">' +
                           ' <div class="chuthich1">' + __ObjText +
                            "</div>" +
                        "</div>";
    $control(__ObjID).innerHTML = __Html;
}

function HideToolTip(__ObjID) {
    $control(__ObjID).style.display = 'none';
}

function SetSizeToolTip(sender, menuId, __add) {
    if (sender) {
        var x = 0, y = 0;
        var w = 0, h = 0;
        w = sender.offsetWidth;
        h = sender.offsetHeight;
        while (sender.offsetParent) {
            x += sender.offsetLeft;
            y += sender.offsetTop;
            sender = sender.offsetParent;
        }
        //  alert(x + ':' + y + ':' + h);
        var popupMenu = $control(menuId);
        if (popupMenu) {
            if (popupMenu.style.display == 'none') {//alert(x);
                popupMenu.style.left = x + __add + 'px';
                popupMenu.style.top = y - 10 + 'px';
                popupMenu.style.display = 'block';
            }
            else {
                popupMenu.style.display = 'none';

            }
        }
    }
    return false;
}
var dtCh = "https://ebank.vtc.vn/";
var minYear = 1900;
var maxYear = 2100;

function stripCharsInBag(s, bag) {
    var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++) {
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary(year) {
    // February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ((!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28);
}
function DaysArray(n) {
    for (var i = 1; i <= n; i++) {
        this[i] = 31
        if (i == 4 || i == 6 || i == 9 || i == 11) { this[i] = 30 }
        if (i == 2) { this[i] = 29 }
    }
    return this
}
function isDate(dtStr) {
    var daysInMonth = DaysArray(12)
    var pos1 = dtStr.indexOf(dtCh)
    var pos2 = dtStr.indexOf(dtCh, pos1 + 1)
    var strMonth = dtStr.substring(0, pos1)
    var strDay = dtStr.substring(pos1 + 1, pos2)
    var strYear = dtStr.substring(pos2 + 1)
    strYr = strYear
    if (strDay.charAt(0) == "0" && strDay.length > 1) strDay = strDay.substring(1)
    if (strMonth.charAt(0) == "0" && strMonth.length > 1) strMonth = strMonth.substring(1)
    for (var i = 1; i <= 3; i++) {
        if (strYr.charAt(0) == "0" && strYr.length > 1) strYr = strYr.substring(1)
    }
    month = parseInt(strMonth)
    day = parseInt(strDay)
    year = parseInt(strYr)
    if (pos1 == -1 || pos2 == -1) {
        // alert("The date format should be : mm/dd/yyyy")
        return false
    }
    if (strMonth.length < 1 || month < 1 || month > 12) {
        // alert("Please enter a valid month")
        return false
    }
    if (strDay.length < 1 || day < 1 || day > 31 || (month == 2 && day > daysInFebruary(year)) || day > daysInMonth[month]) {
        //  alert("Please enter a valid day")
        return false
    }
    if (strYear.length != 4 || year == 0 || year < minYear || year > maxYear) {
        //  alert("Please enter a valid 4 digit year between " + minYear + " and " + maxYear)
        return false
    }
    if (dtStr.indexOf(dtCh, pos2 + 1) != -1 || isInteger(stripCharsInBag(dtStr, dtCh)) == false) {
        // alert("Please enter a valid date")
        return false
    }
    return true
}

function ShowPopup(PopupWidth, PopupHeight, url, title) {
    var popup = $control('ShowPopup');
    var __ClientHeight = document.body.clientHeight > document.body.scrollHeight ? document.body.clientHeight : document.body.scrollHeight;
    __ClientHeight = __ClientHeight < 600 ? 600 : __ClientHeight;
    $control('overlay').style.display = 'block';
    var scrolledX, scrolledY;
    if (self.pageYOffset) {
        scrolledX = self.pageXOffset;
        scrolledY = self.pageYOffset;
    }
    else if (document.documentElement && document.documentElement.scrollTop) {
        scrolledX = document.documentElement.scrollLeft;
        scrolledY = document.documentElement.scrollTop;
    }
    else if (document.body) {
        scrolledX = document.body.scrollLeft;
        scrolledY = document.body.scrollTop;
    }

    var centerX, centerY;
    if (self.innerHeight) {
        centerX = self.innerWidth;
        centerY = self.innerHeight;
    }
    else if (document.documentElement && document.documentElement.clientHeight) {
        centerX = document.documentElement.clientWidth;
        centerY = document.documentElement.clientHeight;
    }
    else if (document.body) {
        centerX = document.body.clientWidth;
        centerY = document.body.clientHeight;
    }

    // Xwidth is the width of the div, Yheight is the height of the
    // div passed as arguments to the function:
    var leftOffset = scrolledX + (centerX - PopupWidth) / 2;
    var topOffset = scrolledY + (centerY - PopupHeight) / 2;
    popup.style.width = parseInt(PopupWidth) + 'px';
    popup.style.height = parseInt(PopupHeight) + 'px';
    popup.style.left = parseInt(leftOffset) + 'px';
    popup.style.top = parseInt(topOffset) + 'px';
    __ClientHeight = __ClientHeight > scrolledY + centerY ? __ClientHeight : scrolledY + centerY;
    var Height = (__ClientHeight - PopupHeight) / 2;
    var Width = (document.body.clientWidth - PopupWidth) / 2;
    $control('overlay').style.height = __ClientHeight + 'px';
    popup.innerHTML = div(parseInt(PopupWidth), parseInt(PopupHeight), parseInt(Width), parseInt(Height), url, title);
    popup.style.display = 'block';
    return false;
}
function div(width, height, left, top, url, title) {
    return '<table width="100%" border=\"0\" cellspacing="0" cellspadding="0"><tr  class="HeadPopup"><td style="text-align:left;width:90%"><h1 id="Modelpopup_title" style="cursor: move;border:none">' + title.toUpperCase() + '</h1></td><td style="text-align:right;width:10%"><h1  id="Modelpopup_title" onclick="UnLoading();UnLoad();" style="cursor: Pointer;border:none">Close</h1></td></tr><tr class="ContentPopup"><td colspan=\"2\" style="text-align:center;width:100%"><iframe width="100%" style="border: none;text-align:left" scrolling="auto" height="' + (height - 14) + '" src="' + url + '"></iframe></td></tr></table>';
}